package com.example.recyclerviewdata305szx.activity;

import android.support.v7.app.AppCompatActivity;
import android.os.Bundle;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.widget.Toast;

import com.example.recyclerviewdata305szx.R;
import com.example.recyclerviewdata305szx.adapter.MyAdapter;
import com.example.recyclerviewdata305szx.bean.ArticleBean;
import com.example.recyclerviewdata305szx.iface.ArticleListener;
import com.example.recyclerviewdata305szx.model.ArticleModel;

import java.util.List;

public class MainActivity extends AppCompatActivity {
    private RecyclerView recyclerView;
    private RecyclerView.LayoutManager layoutManager;
    private MyAdapter myAdapter;
    private List<ArticleBean> list=null;
    ArticleListener articleListener= new ArticleListener() {
        @Override
        public void onResponse(List<ArticleBean> beanList) {
            list=beanList;
            myAdapter.setList(list);
            myAdapter.notifyDataSetChanged();
        }

        @Override
        public void onFail(String msg) {
            Toast.makeText(MainActivity.this, msg, Toast.LENGTH_SHORT).show();
        }
    };




    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_main);
        initRecycleView();
        ArticleModel articleModel=new ArticleModel();
        articleModel.getResultList("article",2,"rv1l2tidbomann2qn86nln6ur2",articleListener);

    }

    private void initRecycleView() {
        recyclerView=(RecyclerView)findViewById(R.id.RecyclerView);
        layoutManager=new LinearLayoutManager(this);
        recyclerView.setLayoutManager(layoutManager);
        recyclerView.setHasFixedSize(true);
        // list=getData();
        myAdapter=new MyAdapter(this);
        myAdapter.setList(list);
        recyclerView.setAdapter(myAdapter);
    }}
